package common;

public class Constant {
    // server
    public static int port = 8888;
    public static String serverIp = "";

    // login
    public static String REGISTER = "register_&qw12#%#dsfe!~&%321]]efwe1236fdz,1=";

    public static String encodeRegister(String username) {
        return REGISTER + username;
    }

    public static String decodeLogin(String in) {
        if (in == null) {
            return "";
        }
        String returnStr = in.replaceFirst(REGISTER, "");
        return returnStr;
    }

    // login status
    public static String REGISTER_SUCCEED = "Welcome";
    public static String SYSTEM = "System";
    public static String REGISTER_FAILED = "Register failed, user name already exist";

    // log out
    public static String LOGOUT = "logout_fwe12&!~;;;,,2,sfew324dbeg";

    public static String encodeLogout(String username) {
        return LOGOUT + username;
    }

    public static String decodeLogout(String in) {
        return in.replaceFirst(LOGOUT, "");
    }

    // message
    public static String MESSAGE = "abi5,;:120cvbnewq``~_;";
    public static String MESSAGE_SPLIT = "%,,:;12@43aibde_32=12!!]jew";

    public static String encodeMessage(Message message) {
        return MESSAGE + message.getTime() + MESSAGE_SPLIT + message.getFrom()
                + MESSAGE_SPLIT + message.getContent();
    }

    public static Message decodeMessage(String s) {
        String[] t = s.replaceFirst(MESSAGE, "").split(MESSAGE_SPLIT);
        return new Message(t[0], t[1], t[2]);
    }
}
